﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	xmlns:local="clr-namespace:Faust.Andrew.MTG.Player"
	xmlns:Faust_Andrew_MTG_Player_Shared="clr-namespace:Faust.Andrew.MTG.Player.Shared;assembly=Faust.Andrew.MTG.Player.Shared"
	x:Class="Faust.Andrew.MTG.Player.PlayersControl"
	x:Name="UserControl">
	<UserControl.Resources>
		<Faust_Andrew_MTG_Player_Shared:Counter x:Key="CounterDataSource" d:IsDataSource="True"/>
		<local:PlayerState x:Key="PlayerStateDataSource" d:IsDataSource="True"/>
		<DataTemplate x:Key="CounterItemTemplate">
			<Grid d:DesignWidth="273">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				<Label HorizontalAlignment="Stretch" Content="{Binding Name, Mode=Default}" d:LayoutOverrides="Height" Margin="0,0,5,0"/>
				<Label HorizontalAlignment="Stretch" Content="{Binding Value, Mode=Default}" d:LayoutOverrides="Height" Grid.Column="1"/>
			</Grid>
		</DataTemplate>
		<DataTemplate x:Key="PlayerItemTemplate">
			<Grid d:DesignWidth="200" Width="Auto" MinWidth="200" Background="#FFC7C7C7" MaxHeight="300" PreviewDrop="Player_PreviewDrop" AllowDrop="True">
				<Grid.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Edit _Counters" Click="EditCounters_Click"/>
					</ContextMenu>
				</Grid.ContextMenu>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="Auto"/>					
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="*"/>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				<Label Margin="0" Content="Name:"/>
				<Label Margin="0" Content="Deck Name:" Grid.Row="1"/>
				<Label Margin="0" Content="Life Counter:" Grid.Row="2" VerticalAlignment="Center"/>
				<Label Margin="0" VerticalAlignment="Stretch" Height="Auto" Content="Deck:" Grid.Row="3"/>
				<Label HorizontalAlignment="Left" Grid.Column="0" Grid.Row="4" Content="Hand:" d:LayoutOverrides="Height"/>
				<Label HorizontalAlignment="Left" Grid.Column="0" Grid.Row="5" Content="Graveyard:" d:LayoutOverrides="Height"/>
				<Label x:Name="lblPlayerName" Margin="0" Content="{Binding Name, Mode=OneWay}" Grid.Column="1" Grid.ColumnSpan="3"/>
				<Label x:Name="lblDeckName" Margin="0" Content="{Binding DeckName, Mode=Default}" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="3"/>
				<Label x:Name="lblLifeCounter" Margin="0" VerticalAlignment="Center" Height="Auto" Content="{Binding LifeCounter, Mode=TwoWay}" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="1"/>
				<Label x:Name="lblDeckCount" Margin="0" Content="{Binding DeckCount, Mode=OneWay}" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="3"/>
				<Label x:Name="lblHandCount" HorizontalAlignment="Stretch" Grid.Row="4" Grid.Column="1" Content="{Binding HandCount, Mode=OneWay}" d:LayoutOverrides="Height" Grid.ColumnSpan="3"/>
				<Label HorizontalAlignment="Stretch" Grid.Row="5" Grid.Column="1" Content="{Binding GraveyardCount, Mode=OneWay}" d:LayoutOverrides="Height" Grid.ColumnSpan="3"/>
				<Button x:Name="btnAddLife" Margin="0,0,5,0" Grid.Column="3" Grid.Row="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="Auto" Click="btnAddLife_Click">
					<Image Margin="0" Width="16" Height="Auto" Source="images/Add.png"/>
				</Button>
				<Button x:Name="btnRemoveLife" Margin="0,0,5,0" VerticalAlignment="Stretch" Height="Auto" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Stretch" Width="Auto" Click="btnRemoveLife_Click">
					<Image Margin="0" Width="16" Height="Auto" Source="images/Delete.png"/>
				</Button>
				<ItemsControl Width="Auto" Height="Auto" Grid.Row="6" Grid.ColumnSpan="4" ItemsSource="{Binding Counters, Converter={StaticResource CounterListConverter}, Mode=OneWay}" ItemsPanel="{DynamicResource PlayerCounterPanelTemplate}" ItemTemplate="{DynamicResource PlayerCounterItemTemplate}" Grid.RowSpan="1"/>
			</Grid>
		</DataTemplate>
		<ItemsPanelTemplate x:Key="PlayerCounterPanelTemplate">
			<WrapPanel IsItemsHost="True"/>
		</ItemsPanelTemplate>
		<DataTemplate x:Key="PlayerCounterItemTemplate">
			<Grid ToolTip="{Binding Name, Mode=OneWay}">
				<Ellipse Fill="{Binding Color, Converter={StaticResource ColorToBrushConverter}, Mode=OneWay}" Stroke="{x:Null}" Width="35" Height="35" HorizontalAlignment="Center" VerticalAlignment="Center"/>
				<Image Panel.ZIndex="1" Source="images/counter.png" Width="40"/>
				<Label Margin="0,0,-0.001,0" Content="{Binding Value, Mode=OneWay}" d:LayoutOverrides="Width, Height" Panel.ZIndex="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
			</Grid>
		</DataTemplate>
	</UserControl.Resources>

	<ScrollViewer>
		<StackPanel>
			<ItemsControl x:Name="playerItemsControl" ItemsSource="{Binding Players, Mode=Default}" ItemTemplate="{DynamicResource PlayerItemTemplate}" ScrollViewer.CanContentScroll="True"/>
		</StackPanel>
	</ScrollViewer>
</UserControl>